import Cookies from 'js-cookie'
import env from './util.env'

const cookies = {}

/**
 * @description 存储 cookie 值
 * @param {String} name cookie name
 * @param {String} value cookie value
 * @param {Object} setting cookie setting
 */
cookies.set = function(name = 'default', value = '', cookieSetting = {}) {
  const key = `platform-${env.VUE_APP_VERSION}-${name}`
  const currentCookieSetting = {}
  Object.assign(currentCookieSetting, cookieSetting)
  Cookies.set(key, value, currentCookieSetting)
  // sessionStorage.setItem(key, value);
}

/**
 * @description 拿到 cookie 值
 * @param {String} name cookie name
 */
cookies.get = function(name = 'default') {
  const key = `platform-${env.VUE_APP_VERSION}-${name}`
  return Cookies.get(key)
  // return sessionStorage.getItem(key);
}

/**
 * @description 删除 cookie
 * @param {String} name cookie name
 */
cookies.remove = function(name = 'default') {
  const key = `platform-${env.VUE_APP_VERSION}-${name}`
  return Cookies.remove(key)
  // return sessionStorage.removeItem(key);
}

export default cookies
